<script>
    // 工具函数之封装判断数据类型的函数
    // Object.prototype.toString()
    function getType(data) {
        if(data === null) return String(data)
        return typeof data === "object" ? Object.prototype.toString.call(data).replace('[object ', '').replace(']', '').toLowerCase() : typeof data
    }

    // 调用
    console.log(getType(null)); // -> null
    console.log(getType(undefined)); // -> undefined
    console.log(getType({})); // -> object
    console.log(getType([])); // -> array
    console.log(getType(123)); // -> number
    console.log(getType(true)); // -> boolean
    console.log(getType('码路')); // -> string
    console.log(getType(/123/)); // -> regexp
    console.log(getType(new Date())); // -> date
</script>























<script>
    // console.log(getType(null)); // -> null
    // console.log(getType(undefined)); // -> undefined
    // console.log(getType({})); // -> object
    // console.log(getType([])); // -> array
    // console.log(getType(123)); // -> number
    // console.log(getType(true)); // -> boolean
    // console.log(getType('码路')); // -> string
    // console.log(getType(/123/)); // -> regexp
    // console.log(getType(new Date())); // -> date
</script>